$(document).ready(function () {
//头像行高设置
    var w = $("#div-rid-a").width();//取得宽度
    $("#div-rid-a").height(w);//设置高度为宽度值
    $("#div-rid-a").css('line-height', w + "px");

    $("#userinfo").click(function () {
        $("#btn-d").css("display", "none");
        $("#btn-c").css("display", "block");
        $("#userinfo").attr("class", "btn-exh-list-ex");
        $("#privilege").attr("class", "btn-exh-list-car");

    });
    $("#privilege").click(function () {
        $("#btn-d").css("display", "block");
        $("#btn-c").css("display", "none");
        $("#userinfo").attr("class", "btn-exh-list-car");
        $("#privilege").attr("class", "btn-exh-list-ex");
    });
    $("#xiugai").click(function () {
        $("#wj", parent.document).css("display", "block");
        $(".shade", parent.document).css("display", "block");
    });
    $("#order-close3", parent.document).click(function () {
        $("#wj", parent.document).css("display", "none");
        $(".shade", parent.document).css("display", "none");
    });
    var user_name;//用户名
    var identity;//身份
    var gosi;//公司名称
    var group2;//行业
    //点击修改信息
    $("#uodateinfo").click(function () {
        data={
            "phone":sessionStorage.phone,
            "login_name":$("#user").val(),
            "card":$("#identity").text(),
            "industry":$("#group2").text(),
            "companyName":$("#gosi").val()
        };
        $.ajax({
            url: "http://www.enet720.net:8080/zwkj/account/updateinfo",
            type: "POST",
            async: true,//异步请求
            data: JSON.stringify(data),
            contentType: "application/json;charset=utf-8",
            timeout: 5000,
            success: function (data) {
                if(data.code=="0"){
                    data={
                        "phone":sessionStorage.phone
                    };
                    ajax(data);
                    $("#myiframe",parent.document).attr("src", "personal-information.html");
                    sessionStorage.login_name=$("#user").text();
                }else{
                    alert("数据异常请重试！")
                }
            },
            error:function () {
                alert("请求超时请重试！");
            }
        });
    });
    var data={
        "phone":sessionStorage.phone
    };
    //加载用户信息
    function ajax(data) {
        $.ajax({
            url: "http://www.enet720.net:8080/zwkj/account",
            type: "POST",
            async: false,//同步请求
            data: JSON.stringify(data),
            contentType: "application/json;charset=utf-8",
            timeout: 5000,
            success: function (data) {
                if(data.code=="0"){
                    $("#user").val(data.data[0].login_name);
                    $("#identity").text(data.data[0].card);
                    if(data.data[0].industry!=null&&data.data[0].industry!=""){
                        $("#group2").text(data.data[0].industry);
                    }
                    if(data.data[0].companyName!=null&&data.data[0].companyName!=""){
                        $("#gosi").val(data.data[0].companyName);
                    }
                }else{
                    alert("数据异常请重试！")
                }
            },
            error:function () {
                alert("请求超时请重试！");
            }
        });
    }
    window.load=ajax(data);
    $("#btn-group2 .dropdown-menu a").click(function () {
        var aa=$(this).text();
        $("#identity").text(aa);
    });
    $("#btn-group1 .dropdown-menu a").click(function () {
        var aa=$(this).text();
        $("#group2").text(aa);
    });
    $("#gosi").focus(function () {
        $(this).val("");
    });
    $("#gosi").blur(function () {
        if($("#gosi").val()==""){
            $("#gosi").val("请您自行填写");
        }
    });
    $("#user").focus(function () {
        $(this).val("");
    });
    $("#user").blur(function () {
        if($("#user").val()==""){
            $("#user").val(sessionStorage.login_name);
        }
    });
    $("#withdraw").click(function () {
        parent.location.href="../HTML/login.html";
    });
});
